//
//  Header.h
//  IceKuangjia
//
//  Created by sanmi on 16/8/5.
//  Copyright © 2016年 sanmi. All rights reserved.
//

#ifndef Header_h
#define Header_h

//如果有Debug这个宏的话,就允许log输出...可变参数
#ifdef DEBUG
#define NSLog(...) NSLog(__VA_ARGS__)
#else
#define NSLog(...)
#endif

//随机色
#define Random_color [UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1]

//字体大小
#define Font(size) [UIFont systemFontOfSize:size];

//屏幕宽
#define WIDTH [UIScreen mainScreen].bounds.size.width
//屏幕高
#define HEIGHT [UIScreen mainScreen].bounds.size.height

/*---------1.设备类-------------------------------------*/

#define StatusHeight ((DEVICE_versionAfter7_0)?0:20)
#define DEVICE_screenHeight     [UIScreen mainScreen].bounds.size.height
#define DEVICE_screenWidth      [UIScreen mainScreen].bounds.size.width
#define DEVICE_versionAfter7_0  ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
//判断是否为iPhone5
#define DEVICE_isiPhone5        ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)

/*---------2.网络类-------------------------------------*/

/*---------3.数据类型-------------------------------------*/
#define TYPE_isDictionary(object)   (object && [object isKindOfClass:[NSDictionary class]])
#define TYPE_isArray(object)        (object && [object isKindOfClass:[NSArray class]])
#define TYPE_isString(object)       (object && [object isKindOfClass:[NSString class]])
/*---------4.系统对象类-------------------------------------*/
#define USERDFAULT_get [[NSUserDefaults standardUserDefaults] objectForKey:key]

#define USERDFAULT_set(object,key) [[NSUserDefaults standardUserDefaults] setObject:object forKey:key]

#define USERDFAULT_remove(key) [[NSUserDefaults standardUserDefaults] removeObjectForKey:key]

#define USERDFAULT_syn [[NSUserDefaults standardUserDefaults] synchronize]

/*---------5.数据处理类-------------------------------------*/
//时间字符串转时间戳
#define DateStr2Timestamp(dataStr,format)\
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];\
[formatter setDateFormat:format];\
NSDate *dateP = [formatter dateFromString:dateStr];\
dateStr = [NSString stringWithFormat:@"%ld", (long)[dateP timeIntervalSince1970]];

//时间戳转时间字符串
#define TimeStamp2NSDateStr(dateStr,format)\
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];\
[formatter setDateFormat:format];\
NSDate *date = [NSDate dateWithTimeIntervalSince1970:dateStr.longlongValue];\
dateStr = [formatter stringFromDate:date];

#define STRING_fromInt(i) [NSString stringWithFormat:@"%d",i]
#define STRING_fromId(i)  [NSString stringWithFormat:@"%@",i]
#define STRING_isEqual(str1,str2) [str1 isEqualToString:str2]
//判断字符串是否为空,返回NSString
#define STRING_judge(str) (!(str == nil || [str isKindOfClass:[NSNull class]]) ? str : @"")

#define STRING_joint(str1,str2) [NSString stringWithFormat:@"%@%@",str1,str2]
#define URL(str) [NSURL URLWithString:str]
//解码
#define UTF8_decode(str)  [str stringByRemovingPercentEncoding]
//编码
#define UTF8_encode(str)  [str stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]
#endif /* Header_h */
